package com.sugar.subscribe.course.module.business.controller.app.serviceclass;

import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.framework.common.util.object.BeanUtils;
import com.sugar.subscribe.course.module.business.controller.admin.serviceclass.vo.ServiceClassRespVO;
import com.sugar.subscribe.course.module.business.controller.app.serviceclass.vo.AppServiceClassRespVO;
import com.sugar.subscribe.course.module.business.dal.dataobject.serviceclass.ServiceClassDO;
import com.sugar.subscribe.course.module.business.service.serviceclass.ServiceClassService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;

import java.util.List;

import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 服务分类")
@RestController
@RequestMapping("/biz/service-class")
@Validated
public class AppServiceClassController {

    @Resource
    private ServiceClassService serviceClassService;

    @GetMapping("/get/home")
    @Operation(summary = "获取首页分类")
    @PermitAll
    public CommonResult<List<AppServiceClassRespVO>> getHomeServiceClass() {
        return success(serviceClassService.getHomeServiceClass());
    }

    @GetMapping("/get/all/two")
    @Operation(summary = "获取所有二级分类")
    @PermitAll
    public CommonResult<List<AppServiceClassRespVO>> getTwoServiceClass() {
        return success(serviceClassService.getTwoServiceClass());
    }

    @GetMapping("/list")
    @Operation(summary = "根据ParentId获取分类")
    @PermitAll
    public CommonResult<List<AppServiceClassRespVO>> getServiceClassByParentId(@RequestParam(value = "parentId", required = false) Long parentId) {
        if (parentId == null)
            parentId = 0L;
        return success(serviceClassService.getServiceClassByParentId(parentId));
    }

    @GetMapping("/tree")
    @Operation(summary = "获取树形列表")
    @PermitAll
    public CommonResult<List<AppServiceClassRespVO>> getServiceClassTree() {
        return success(serviceClassService.getServiceClassTree());
    }
}